package zwp.example.demo1;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import zwp.example.demo1.demo_pojo.pojo.PojoLocalTimeFormat;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@SpringBootTest
public class Demo3LocalDateTIme{

    @Test
    public void test1(){
        PojoLocalTimeFormat pojoLocalTimeFormat = new PojoLocalTimeFormat();
        LocalTime now = LocalTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
        String format = now.format(formatter);
        pojoLocalTimeFormat.setTime(now);
        System.out.println(format);
    }

    @Test
    public void test2(){
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        String parse = simpleDateFormat.format(date);
        LocalDate now = LocalDate.now();
        LocalDate lastDay = now.minusDays(1);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        String format = now.format(formatter);
        LocalTime now1 = LocalTime.now();
        String s = LocalTime.now().toString();
        SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
        String format1 = now1.format(DateTimeFormatter.ofPattern("HH:mm"));
        System.out.println(now1+"----"+s+"-----"+format1);
    }



    @Test
    public void test3(){

        String format = LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE);
        System.out.println("format = " + format);
        LocalDate localDate = LocalDate.now().plusDays(1);
        Date from = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(from);
        System.out.println(simpleDateFormat.format(from));
    }
}
